package com.sansecy.monitor.see;

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description TODO
 * @Date 2019-08-04 01:44
 * @Created by caoyu
 */
public class ActivityManger {
    private static List<Activity> sActivities = new ArrayList<>();
    private static List<Fragment> sFragments = new ArrayList<>();

    public ActivityManger() {
    }

    public static Activity getTopActivity() {
        return sActivities.get(0);
    }
    public static void addActivity(Activity activity) {
        sActivities.add(0, activity);
    }

    public static void removeActivity(Activity activity) {
        sActivities.remove(activity);
    }

    public static void addFragment(Fragment fragment) {
        sFragments.add(0,fragment);
    }

    public static void removeFragment(Fragment fragment) {
        sFragments.remove(fragment);
    }

    public static List<Activity> getActivitys() {
        return new ArrayList<>(sActivities);
    }

    public static List<Fragment> getFragments() {
        return new ArrayList<>(sFragments);
    }

    public static List<Fragment> getFragment(FragmentActivity fragmentActivity) {
        return fragmentActivity.getSupportFragmentManager().getFragments();
    }

    public static List<Fragment> getFragment(Fragment fragment) {
        return fragment.getChildFragmentManager().getFragments();
    }

}
